package com.badibadi.mail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.badibadi.activity.BaseActivity;
import com.badibadi.activity.SelectPictsMail_Activity;
import com.badibadi.activity.ShowViewPagerActivity;
import com.badibadi.adapter.GridViewListAdapter;
import com.badibadi.adapter.Gridview3Adapter;
import com.badibadi.infos.Img;
import com.badibadi.infos.PayUserContactShow1Model;
import com.badibadi.infos.PayUserContactShow2Model;
import com.badibadi.infos.Results;
import com.badibadi.infos.Zhannei_usercontactModel;
import com.badibadi.mail.MailNozixunfeiActivity.MySpSizeAdapter;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.RegexUtils;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.ViewHolder;
import com.badibadi.mytools.XUtils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.badibadi.uniclubber.R.layout;
import com.libjph.util.StringUtil;
import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * activity_mail_send 没有咨询费的界面，可以相互聊 Adapter
 * 
 * @author Administrator activity_mail_send mail_biaoqing niming
 *         activity_mail_send
 */
public class MailNozixunfeiActivity extends BaseActivity implements
		OnClickListener {
	// 匿名头像地址
	public String nimingHead = Constants.BadiDownImgUrl
			+ "/Public/Uploads/1.png";
	private static final int BiaoQing = 8081;
	private ImageButton btn_textSize_Setting, btn_chuxi, btn_xiezhi,
			btn_xiahuaxian, btn_biaoqin, btn_paizhao, btn_movies;
	private Intent intent = null;
	private String[] ssp = { "5", "10", "15", "20", "25", "30", "35", "40",
			"45", "50" };
	protected EditText activity_mail_content, et_zhuzhi;
	protected TextView activity_mail_send, title_mail, clubAllPeople;
	protected ImageView activity_mail_titalimg;
	protected ListView mail_nozixunfei_list;
	protected MailZhanneiListAdapter listAdapter;
	private Results results, results2;
	private PayUserContactShow2Model contactShow2Model;
	private List<Zhannei_usercontactModel> list;
	private ImageView activity_mail_delete;
	private String msgId = "", title = "", is_fee = "", sent_uid = "",
			rank = "";
	ListView lv;// 文字大小列表

	AlertDialog textdialog;
	/**
	 * 加粗 TextView tv = (TextView)findViewById(R.id.TextView01); TextPaint tp =
	 * tv.getPaint(); tp.setFakeBoldText(true);
	 * 
	 * login_registration.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //添加线
	 * //login_edit_username.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
	 * //删除线
	 */
	/**
	 * 是否是粗体
	 */
	private boolean isChuti = false;
	/**
	 * 是否是斜体
	 */
	private boolean isXieti = false;
	/**
	 * 是否有下划线
	 */
	private boolean hasXiahuaxian = false;

	// //用于判断是否需要咨询费（本activity的）
	// UserInfoModel userInfoModel;
	// String ask;//问方
	// private String answer;//答方
	// // private String answerName;
	// String is_anonymity;//是否匿名
	// private String is_fee;//是否需要咨询费
	private CheckBox niming;
	private String is_niming = null;
	private String zhannei_id = null;
	private DisplayImageOptions options;
	// PayUserContactShow1Model payUserContactShow1Model;
	// 下面的是照相机的
	private ArrayList<String> pathlist;
	private GridView picGridView;
	ArrayList<Img> imgs;
	Gridview3Adapter picGridView_adapter;
	ArrayList<String> htmp_list;
	private LinearLayout niming_linear;
	public Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 6:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);

				PeiZhi();
				break;
			case 8:
				try {
					Utils.ExitPrgress(MailNozixunfeiActivity.this);
					Utils.showMessage(MailNozixunfeiActivity.this,
							results2.getRetmsg());
					finish();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 7:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources().getString(R.string.l_xa10));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources()
									.getString(R.string.wx_caozuo_success));
					Constants.is_shuaxin=true;
					finish();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources().getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 4:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources().getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 5:// 答方的资料显示
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				try {
					Utils.showMessage(MailNozixunfeiActivity.this,
							getResources().getString(R.string.l_xb12));

				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2000:
				Utils.ExitPrgress(MailNozixunfeiActivity.this);
				Utils.ExitProgress_hen(MailNozixunfeiActivity.this);
				Utils.showMessage(MailNozixunfeiActivity.this, getResources()
						.getString(R.string.l_xb18));
				String temp_path = msg.getData().getString("path");
				htmp_list = new ArrayList<String>();
				htmp_list = fenge(temp_path);

				for (int i = 0; i < htmp_list.size(); i++) {
					// activity_mail_content.setText(activity_mail_content
					// .getText().toString() + list3.get(i));
					// activity_mail_content.setSelection(activity_mail_content
					// .getText().toString().length());
					Img img = new Img();
					String cc = htmp_list.get(i).substring(10,
							htmp_list.get(i).length() - 4);
//					   
					img.setPath(cc);
					imgs.add(img);
				}
				picGridView_adapter.notifyDataSetChanged();

				break;
			default:
				break;
			}
		}

	};

	private ArrayList<String> fenge(String ds) {
		String dg[] = ds.split(",");
		ArrayList<String> list2 = new ArrayList<String>();
		if (dg != null) {
			for (int i = 0; i < dg.length; i++) {
				// <img
				// src='http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/7a/shenshou_thumb.gif'
				// />"
				if (dg[i].startsWith("http")) {
					list2.add("<img src='" + dg[i] + "' />");
				} else {
					list2.add("<img src='" + Constants.BadiDownImgUrl + dg[i]
							+ "' />");
				}
			}
		}
		return list2;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_mail_nozixunfei);
		Constants.is_shuaxin=false;
		int test = MailActivity.ALLMAIL;
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		// payUserContactShow1Model = (PayUserContactShow1Model) getIntent()
		// .getSerializableExtra("payUserContactShow1Model");
		zhannei_id = getIntent().getStringExtra("id");
//		   
		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						// Intent intent = new
						// Intent(MailNozixunfeiActivity.this,
						// Mail8_14_15Activity.class);
						// intent.putExtra("payUserContactShow1Model",
						// payUserContactShow1Model);
						// startActivity(intent);
						finish();
					}
				});

		niming = (CheckBox) this.findViewById(R.id.check_niming);
		init();

	}

	public void init() {
		// TODO Auto-generated method stub
		// cid=getIntent().getStringExtra("cid");
		// admin_uid=getIntent().getStringExtra("admin_uid");
		// clubname=getIntent().getStringExtra("clubname");
		niming_linear = (LinearLayout) this.findViewById(R.id.niming_linear);
		picGridView = (GridView) this.findViewById(R.id.picture_GridView);
		picGridView.setHorizontalSpacing(DisplayUtil.dip2px(
				MailNozixunfeiActivity.this, 5));
		picGridView.setVerticalSpacing(DisplayUtil.dip2px(
				MailNozixunfeiActivity.this, 5));
		imgs = new ArrayList<Img>();

		picGridView_adapter = new Gridview3Adapter(MailNozixunfeiActivity.this,
				imgs);
		picGridView.setAdapter(picGridView_adapter);
		picGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long arg3) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MailNozixunfeiActivity.this,
						ShowViewPagerActivity.class);
				intent.putStringArrayListExtra("pic",
						(ArrayList<String>) picGridView_adapter.getSList());
				intent.putExtra("position", position);
				startActivity(intent);
			}
		});
		pathlist = new ArrayList<String>();

		et_zhuzhi = (EditText) this.findViewById(R.id.et_zhuzhi);
		list = new ArrayList<Zhannei_usercontactModel>();
		btn_textSize_Setting = (ImageButton) this
				.findViewById(R.id.mail_textSize_Setting);
		btn_textSize_Setting.setOnClickListener(MailNozixunfeiActivity.this);

		btn_chuxi = (ImageButton) this.findViewById(R.id.mail_chuxi);
		btn_chuxi.setOnClickListener(MailNozixunfeiActivity.this);
		btn_xiezhi = (ImageButton) findViewById(R.id.mail_xie_zhi);
		btn_xiezhi.setOnClickListener(this);
		btn_xiahuaxian = (ImageButton) this.findViewById(R.id.mail_xiahuaxian);
		btn_xiahuaxian.setOnClickListener(this);

		activity_mail_delete = (ImageView) this
				.findViewById(R.id.activity_mail_delete);
		activity_mail_delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				delete(Utils.getUid(MailNozixunfeiActivity.this), zhannei_id,
						"zhannei_usercontact", rank, handler);
			}
		});
		activity_mail_content = (EditText) findViewById(R.id.activity_mail_content);
		activity_mail_titalimg = (ImageView) findViewById(R.id.activity_mail_titalimg);
		mail_nozixunfei_list = (ListView) findViewById(R.id.mail_nozixunfei_list);
		listAdapter = new MailZhanneiListAdapter();
		mail_nozixunfei_list.setAdapter(listAdapter);
		title_mail = (TextView) findViewById(R.id.title_mail);

		niming.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (isChecked) {
					is_niming = "1";
				} else {
					is_niming = "0";
				}
			}
		});
		btn_paizhao = (ImageButton) findViewById(R.id.mail_paizhao);
		btn_paizhao.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MailNozixunfeiActivity.this,
						SelectPictsMail_Activity.class);
				intent.putExtra("panduan", "no_set");
				startActivityForResult(intent, 3);
			}
		});

		this.findViewById(R.id.mail_biaoqing).setOnClickListener(this);
		// PeiZhi();
		showUserContact(zhannei_id);
	}

	/**
	 * 站内信无咨询费
	 * 
	 * @param zhanneiId
	 */
	private void showUserContact(final String zhanneiId) {
		Utils.showPrgress(MailNozixunfeiActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", Utils.getUid(MailNozixunfeiActivity.this));
				map.put("zhanneiId", zhanneiId);
//				   
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "inform/showUserContact");
				if (content != null) {
					results = Utils.checkResult_NNN(getApplicationContext(),
							content);
//					   
					if (results != null && !results.getRetmsg().equals("null")
							&& results.isRet()) {
						try {
							contactShow2Model = JSONUtils
									.getEntityByJsonString(results.getRetmsg(),
											PayUserContactShow2Model.class);
							handler.sendEmptyMessage(6);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(7);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void unPaySentMsg(final String re_uid, final String msgId,
			final String title, final String content, final String is_fee,
			final String is_anonymity) {
		Utils.showPrgress(MailNozixunfeiActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("sent_uid", Utils.getUid(MailNozixunfeiActivity.this));// 发送者ID（登录用户）
				map.put("re_uid", re_uid);// 接收者ID（收信者）
				map.put("msgId", msgId);// 回复的消息(用户联系消息)ID(注意，此处不是站内信ID)
				map.put("title", title);// 站内信主旨
				map.put("content", content);// 站内信内容
				map.put("is_fee", is_fee);// 是否需要咨询费（注意，本接口的$is_fee必须为0）
				map.put("is_anonymity", is_anonymity);// 是否匿名 只有问方才可以匿名 0：否 1：是
//				   
//						+ "inform/unPaySentMsg" + "   " + map.toString());
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "inform/unPaySentMsg");
				if (content != null) {
					results2 = Utils.checkResult_NNN(getApplicationContext(),
							content);
//					   
					if (results2 != null
							&& !results2.getRetmsg().equals("null")
							&& results2.isRet()) {
						handler.sendEmptyMessage(8);
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void PeiZhi() {
		// TODO Auto-generated method stub
		// TextView content1 = (TextView) this.findViewById(R.id.content1);
		// new HtmlUtils(MailNozixunfeiActivity.this, content1,
		// contactShow2Model
		// .getContent().get(0).getContents()).showTextView();
		if (contactShow2Model.getContent() != null) {
			list.clear();
			list = contactShow2Model.getContent();
		}
		is_niming = contactShow2Model.getIs_anonymity();
		// for (int i = list.size() - 1; i >= 0; i--) {
		if (!Utils.getUid(MailNozixunfeiActivity.this).equals(
				list.get(0).getSent_uid())) {
			sent_uid = list.get(0).getSent_uid();
			msgId = list.get(0).getId();
			title = list.get(0).getTitle();
			is_fee = list.get(0).getIs_fee();
		}
		// }

		// if (sent_uid == null) {
		// for (int i = list.size() - 1; i >= 0; i--) {
		// if (Utils.getUid(MailNozixunfeiActivity.this).equals(
		// list.get(i).getSent_uid())) {
		// sent_uid = list.get(i).getRe_uid();
		// msgId = list.get(i).getId();
		// title = list.get(i).getTitle();
		// is_fee = list.get(i).getIs_fee();
		// break;
		// }
		// }
		// }

		if (contactShow2Model.getSent_uid().equals(
				Utils.getUid(MailNozixunfeiActivity.this))) {
			rank = "asker";// 我是问方
		} else {
			rank = "answerer";
		}
		if (contactShow2Model.getIs_anonymity().equals("1")) {
			niming.setChecked(true);
		} else if (contactShow2Model.getIs_anonymity().equals("0")) {
			niming.setChecked(false);
		} else {
			niming.setChecked(false);
		}

		et_zhuzhi.setText(getResources().getString(R.string.wx_reply_kuohao)
				+ title);

		TextView shoujianfang = (TextView) this.findViewById(R.id.shoujianfang);

		if (contactShow2Model.getReceive() == null) {
			shoujianfang.setText(getResources().getString(
					R.string.wx_Anonymous_user));
		} else {
			shoujianfang.setText(""
					+ contactShow2Model.getReceive().getNickName());
		}
		listAdapter.notifyDataSetChanged();
		// 发送

		this.findViewById(R.id.activity_mail_send).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						// answer();
						String content = activity_mail_content.getText()
								.toString().trim();
						String zhuzhi = et_zhuzhi.getText().toString().trim();
						if (!Utils.getUid(MailNozixunfeiActivity.this).equals(
								list.get(0).getSent_uid())) {
							if (!StringUtil.isNullOrEmpty(content)) {
								if (!StringUtil.isNullOrEmpty(zhuzhi)) {
									StringBuffer buff = new StringBuffer(
											content);
									if (imgs != null && !imgs.isEmpty()) {
										buff.append("<div>");
										for (int i = 0; i < imgs.size(); i++) {
											buff.append(Utils.toMailHtmL(imgs
													.get(i).getPath()));
											//    
										}
										buff.append("<div style='clear:both;'></div></div>");
									}
									String content3 = buff.toString().trim();
									//    
									String content2 = SinaExpressionTools
											.replaceAllReplaceToPath(content3);
									content2 = content2.replaceAll("\\[", "");
									content2 = content2.replaceAll("\\]", "");
									unPaySentMsg(sent_uid, msgId, zhuzhi,
											content2, is_fee, is_niming);
								} else {
									Utils.showMessage(
											MailNozixunfeiActivity.this,
											getResources().getString(
													R.string.wx_txt_114));
								}
							} else {
								Utils.showMessage(
										MailNozixunfeiActivity.this,
										getResources().getString(
												R.string.wx_txt_81));
							}
						} else {
							Utils.showMessage(
									MailNozixunfeiActivity.this,
									getResources().getString(
											R.string.wx_txt_113));
						}
					}
				});
		// if (!list.isEmpty()) {
		// if (Utils.getUid(MailNozixunfeiActivity.this).equals(
		// list.get(list.size() - 1).getSent_uid())) {
		// niming_linear.setVisibility(View.VISIBLE);
		// } else {
		// niming_linear.setVisibility(View.GONE);
		// }
		// }

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.mail_xie_zhi:
			ChangeXieti();
			break;
		case R.id.mail_textSize_Setting:
			initDialog();
			break;
		case R.id.mail_chuxi:
			ChangeChuti();
			// if (isChuti) {
			// isChuti = false;
			// } else {
			// isChuti = true;
			// }
			break;
		case R.id.mail_xiahuaxian:
			ChangeXiaHuaXian();
			break;
		case R.id.mail_biaoqing:
			Intent intent = new Intent(MailNozixunfeiActivity.this,
					SinaExpressionActivity.class);
			startActivityForResult(intent, BiaoQing);
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		// if (keyCode == 4) {
		// Intent intent = new Intent(MailNozixunfeiActivity.this,
		// Mail8_14_15Activity.class);
		// intent.putExtra("payUserContactShow1Model",
		// payUserContactShow1Model);
		// startActivity(intent);
		// finish();
		// }

		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		// TODO Auto-generated method stub
		if (arg0 == BiaoQing
				&& arg1 == SinaExpressionActivity.ACTIVITY_BIAOQING) {
			if (arg2 != null) {
				// String con1 = activity_mail_content.getText().toString();
				// String con2 = arg2.getStringExtra("result");
				// activity_mail_content.setText(con1 + con2);
				// activity_mail_content.setSelection((con1 + con2).length());
				String content2 = arg2.getStringExtra("result");
				int index = activity_mail_content.getSelectionStart();
				Editable edit = activity_mail_content.getEditableText();
				edit.insert(index, content2);
			}

		}
		if (arg0 == 3 && arg1 == SelectPictsMail_Activity.HUICHUAN_KEY_1) {
			if (arg2 != null) {
				pathlist = arg2.getStringArrayListExtra("files");
				// Utils.showMessage(MailNozixunfeiActivity.this, getResources()
				// .getString(R.string.l_xb46));
				XUtils.UpImg_ceshi_douhaoXUtils(pathlist,
						MailNozixunfeiActivity.this, handler);
			}
		}

		super.onActivityResult(arg0, arg1, arg2);
	}

	private void initDialog() {
		lv = new ListView(MailNozixunfeiActivity.this);
		// lv.setChoiceMode(choiceMode);
		// ArrayAdapter<Integer> arr=new
		// ArrayAdapter<Integer>(getApplicationContext(), resource,
		// textViewResourceId, objects)
		final MySpSizeAdapter spAdapter = new MySpSizeAdapter();
		lv.setAdapter(spAdapter);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// TODO Auto-generated method stub
				setTextSize(Float.parseFloat((String) spAdapter
						.getItem(position)));
				if (textdialog != null) {
					textdialog.dismiss();
				}

			}
		});
		textdialog = new AlertDialog.Builder(MailNozixunfeiActivity.this)
				.setTitle(getResources().getString(R.string.l_xb90))
				.setView(lv).show();
	}

	/**
	 * 设置字体大小
	 * 
	 * @param content
	 */
	private void setTextSize(Float content) {
		activity_mail_content.setTextSize(content);
	}

	/**
	 * 设置粗体和取消粗体
	 */
	private void ChangeChuti() {
		if (isChuti == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 粗体
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isChuti = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isChuti = false;
		}
		hasXiahuaxian = false;
		isXieti = false;
	}

	/**
	 * 设置字体下划线
	 */
	private void ChangeXiaHuaXian() {
		if (hasXiahuaxian == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new UnderlineSpan(), 0, msp.length(),
					Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			// msp.setSpan(new UnderlineSpan(), 27, 30,
			// Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			hasXiahuaxian = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.getPaint().setFakeBoldText(false);
			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			hasXiahuaxian = false;
		}

		isChuti = false;
		isXieti = false;

	}

	/**
	 * 设置斜体和取消斜体
	 */
	private void ChangeXieti() {
		if (isXieti == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 斜体
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isXieti = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.getPaint().setFakeBoldText(false);
			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isXieti = false;
		}

		isChuti = false;
		hasXiahuaxian = false;
	}

	public class MySpSizeAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return ssp.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return ssp[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			LayoutInflater inflater = LayoutInflater
					.from(MailNozixunfeiActivity.this);
			convertView = inflater
					.inflate(R.layout.mail_sp_import_layout, null);

			TextView tv = (TextView) convertView
					.findViewById(R.id.mail_import_sp);
			tv.setText("" + ssp[position]);
			tv.setTextSize(Integer.parseInt(ssp[position]));
			// Typeface face=Typeface.createFromAsset(getAssets(),
			// "founts/cukaitijian.ttf");
			// tv.setTypeface(face);
			// Paint p=new Paint();
			// p.setTextSkewX(-1);
			return convertView;
		}
	}

	private class MailZhanneiListAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			String sender_id = null;
			String receive_id = null;
			LayoutInflater inflater = LayoutInflater
					.from(MailNozixunfeiActivity.this);
			if (convertView == null) {
				convertView = ViewHolder.buildView(MailNozixunfeiActivity.this,
						R.layout.mail_no_zhannei_item, parent);// inflater.inflate(R.layout.mail_no_zhannei_item,
																// null);
				// convertView =
				// ViewHolder.buildView(context,R.layout.manage_club_child_layout1,
				// parent);
			}
			ViewHolder viewHolder = (ViewHolder) convertView.getTag();
			// convertView = inflater.inflate(R.layout.mail_no_zhannei_item,
			// null);
			TextView zhannei_item_content = viewHolder
					.getViewById(R.id.zhannei_item_content);
			TextView time = viewHolder.getViewById(R.id.time);
			ImageView head = viewHolder.getViewById(R.id.head);
			TextView title = viewHolder.getViewById(R.id.title);
			TextView nickName = viewHolder.getViewById(R.id.nickName);
			GridView item_gridView = viewHolder.getViewById(R.id.item);

			// //获取所有的包含图片的<src= >类似的html语言
			List<String> slist = null;
			if (list.get(position).getContents() != null) {
				slist = RegexUtils.getImgSrc(list.get(position).getContents());
				// for (int i = 0; i < slist.size(); i++) {
				// // LogUtils.d("列表是：==》" + list.get(i).toString());
				// }

			}
			// 把图片区分开来
			if (slist != null && !slist.isEmpty()) {
				item_gridView.setVisibility(View.VISIBLE);
//				LogUtils.d("列表是：==》不是空");
				GridViewListAdapter adapter = new GridViewListAdapter(
						MailNozixunfeiActivity.this, slist);
				item_gridView.setAdapter(adapter);
				String aa = list.get(position).getContents();
				List<String> listgroup = RegexUtils.getImgSrcGroup(aa);
				for (int i = 0; i < listgroup.size(); i++) {

					// <img src=' ' />
					if (listgroup.get(i)
							.indexOf(Constants.Fei_biaoqing_qianzui) != -1
							|| listgroup.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui2) != -1
							|| listgroup.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui3) != -1
							|| listgroup.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui4) != -1)
						aa = aa.replaceAll(listgroup.get(i), "");// ("<img src='"+list.get(i)+"' />","");

				}

				new HtmlUtils(MailNozixunfeiActivity.this,
						zhannei_item_content, aa).showTextView();
				// zhannei_item_content.setText(aa);
//				LogUtils.d("aa=" + aa);
				// <img src=' '/ >

			} else if (slist == null || slist.isEmpty()) {
//				LogUtils.d("列表是：==》是空");
				new HtmlUtils(MailNozixunfeiActivity.this,
						zhannei_item_content, list.get(position).getContents())
						.showTextView();
				// zhannei_item_content.setText(list.get(position).getContents());
				item_gridView.setVisibility(View.GONE);
			}
			// new HtmlUtils(MailNozixunfeiActivity.this, zhannei_item_content,
			// list.get(position).getContents(),180).showTextView();
			// // contactShow2Model]

			title.setText(getResources().getString(R.string.wx_zhuzhi_maohao)
					+ list.get(position).getTitle());
			if (contactShow2Model.getSenter() != null)
				sender_id = contactShow2Model.getSenter().getId();
			if (contactShow2Model.getReceive() != null)
				receive_id = contactShow2Model.getReceive().getId();
			try {
				time.setText(""
						+ CalendarTools.getTimeChangeToString(
								MailNozixunfeiActivity.this, list.get(position)
										.getTime()));
			} catch (Exception e) {
				// TODO: handle exception
			}

			// 发送的方的id和接受方的id都不是空
			if (sender_id != null && receive_id != null) {
				if (list.get(position).getSent_uid().equals(sender_id)) {
					ImageLoader.getInstance().displayImage(
							Constants.BadiDownImgUrl + "/"
									+ contactShow2Model.getSenter().getHead(),
							head, options);
					nickName.setText(""
							+ contactShow2Model.getSenter().getNickName());

				} else if (list.get(position).getSent_uid().equals(receive_id)) {
					ImageLoader.getInstance().displayImage(
							Constants.BadiDownImgUrl + "/"
									+ contactShow2Model.getReceive().getHead(),
							head, options);
					nickName.setText(""
							+ contactShow2Model.getReceive().getNickName());
				}
			}
			if (sender_id == null || receive_id == null) {// *
															// 2、当最后一条为本人发送时且对方匿名
				if (sender_id != null) {
					if (list.get(position).getSent_uid().equals(sender_id)) {
						ImageLoader.getInstance().displayImage(
								Constants.BadiDownImgUrl
										+ "/"
										+ contactShow2Model.getSenter()
												.getHead(), head, options);
						nickName.setText(""
								+ contactShow2Model.getSenter().getNickName());
					} else {// 改为匿名头像
						ImageLoader.getInstance().displayImage(nimingHead,
								head, options);
						nickName.setText(getResources().getString(
								R.string.wx_Anonymous_user));
					}

				} else if (receive_id != null) {
					if (list.get(position).getSent_uid().equals(receive_id)) {
						ImageLoader.getInstance().displayImage(
								Constants.BadiDownImgUrl
										+ "/"
										+ contactShow2Model.getReceive()
												.getHead(), head, options);
						nickName.setText(""
								+ contactShow2Model.getReceive().getNickName());
					} else {
						// 改为匿名头像
						ImageLoader.getInstance().displayImage(nimingHead,
								head, options);
						nickName.setText(getResources().getString(
								R.string.wx_Anonymous_user));
					}
				}
			}

			// time.setText(list.get(position).getContents());
			//
			// if(list.get(position).getSent_uid().equals(""+Utils.getUid(MailNozixunfeiActivity.this)))
			// {
			//
			// }
			// ImageLoader.getInstance().displayImage(uri, imageView, options);
			return convertView;
		}

	}

	/*
	 * 有咨询费，答方回复问方数据处理（第一次回复和第二次回复）---POST
	 * 
	 * @param $zhaneniId 站内信ID
	 * 
	 * @param $uid 登录用户（答方）
	 * 
	 * @param $reply_id 回复的是哪一条用户消息ID
	 * 
	 * @param $title 回复的主旨
	 * 
	 * @param $content 回复的内容
	 */
	public void answer() {
		Map<String, Object> map = new HashMap<String, Object>();
		// map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
		map.put("uid", Utils.getUid(MailNozixunfeiActivity.this));
		// map.put("reply_id", payUserContactShow1Model.getContent_id());
		map.put("title", et_zhuzhi.getText().toString());
		map.put("content", activity_mail_content.getText().toString());
		CommonUtils.CommomPostfunction(MailNozixunfeiActivity.this,
				Constants.BadiUrl_1 + "/" + "inform/answer", map, handler, 1,
				5, 2, 3);
	}

	/**
	 * 删除站内信操作---POST
	 * 
	 * @param $uid
	 *            ---登录用户ID
	 * @param $zhanneiId
	 *            ----站内信ID
	 * @param $type
	 *            ----删除的站内信类型 zhannei_usercontact：用户联系 zhannei_clubnotice：俱乐部通知
	 *            zhannei_contactclub：联系俱乐部
	 * @param $rank
	 *            ---操作者的身份 asker：问方 answerer：答方 注意：当为“用户联系”才有该参数
	 */
	private void delete(String uid, String zhanneiId, String type, String rank,
			android.os.Handler handler) {
		Utils.showPrgress(MailNozixunfeiActivity.this);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("zhanneiId", zhanneiId);
		map.put("type", type);
		// if (type.equals("zhannei_usercontact")) {
		map.put("rank", rank);
		// }
//		   
		CommonUtils.CommomPostfunction(MailNozixunfeiActivity.this,
				Constants.BadiUrl_1 + "/" + "inform/delete", map, handler, 1,
				5, 2, 3);
	}
}
